* Code for JEPS replication files
* October 8, 2015
* Cooperating With the State: Evidence from Survey Experiments on Policing

clear
use "CWTS raw data.dta"

rename q1_вар q1var
rename q5_вар q5var
rename q2_вар q2var
rename q3_вар q3var
rename q4_вар q4var

recode q1_1-q1_4 q2_1-q2_4 q3_1-q3_4 q4_1-q4_4 q5_1-q5_4 (2=1)(3=2)(4=3)(5=4)(6=5)(7=.)

sum q1_1-q1_4
gen full1=.
replace full1=q1_1 if full==.
replace full1=q1_2 if full==.
replace full1=q1_3 if full==.
replace full1=q1_4 if full==.

sum q2_1-q2_4
gen full2=.
replace full2=q2_1 if full2==.
replace full2=q2_2 if full2==.
replace full2=q2_3 if full2==.
replace full2=q2_4 if full2==.

sum q3_1-q3_4
gen full3=.
replace full3=q3_1 if full3==.
replace full3=q3_2 if full3==.
replace full3=q3_3 if full3==.
replace full3=q3_4 if full3==.

sum q4_1-q4_4
gen full4=.
replace full4=q4_1 if full4==.
replace full4=q4_2 if full4==.
replace full4=q4_3 if full4==.
replace full4=q4_4 if full4==.

sum q5_1-q5_4
gen full5=.
replace full5=q5_1 if full5==.
replace full5=q5_2 if full5==.
replace full5=q5_3 if full5==.
replace full5=q5_4 if full5==.

recode q1 q2 q3 q4a q4b q4c q5 q6 q7 q8 q59-q67 (99=.)
recode q57a q33* q49 q9* q35 q36 q47 q37 q4a q4b q4c q4d (99=.)

recode q60 (2 1939/1999=1)(2000/2011 = 0), gen(q60fix)

recode q35 q36 q37 q47 q57a (2=0)
recode q9* q33* q49 (5=1)(4=2)(2=4)(1=5)

gen q12=q12_1+q12_2+q12_3+q12_4+q12_5+q12_6+q12_7

replace q1var = . if q1var == 0
recode q1var (1 2 = 1)(3 4 = 0), gen(police)
recode q1var (1 2 = 0)(3 4 = 1), gen(stranger)
recode q1var (2 4 = 1)(1 3 = 0), gen(beating)
gen policeXbeating=police*beating
gen strangerXbeating=stranger*beating
replace q5var = . if q5var == 0
recode q5var (2 4 = 1)(1 3 = 0), gen(duty)
recode q5var (3 4 = 1)(1 2 = 0), gen(reward)
gen dutyXreward=duty*reward
replace q2var = . if q2var == 0
recode q2var (2 4 = 1)(1 3 = 0), gen(busy)
recode q2var (3 4 = 1)(1 2 = 0), gen(highval)
gen busyXhighval=busy*highval

gen beatingXbusy=beating*busy
gen beatingXhighval=beating*highval
gen beatingXbusyXhighval=beating*busy*highval

gen beatingXduty=beating*duty
gen beatingXreward=beating*reward
gen beatingXdutyXreward=beating*duty*reward

gen age=q1/100
*gen male=q2
*replace male = 0 if male == 2
recode q2 (2=1)(3=0), gen(male)
*gen material=q3
recode q3 (2=1)(3=2)(4=3)(5=4)(6=5)(7=6)(8=.), gen(material)
gen edu=q5-1
recode q12_8 (2=0)(1=1), gen(contact_any)
replace contact_any=. if q12_9==2
recode q14 (2=0)(3 4=1)(99 5=.), gen(crimein12mo)
*gen polstaknow=q35  			
recode q35 (0=1)(3=0), gen(polstaknow)
recode q60fix (1=0)(0=1), gen(newmoscow) 			
recode q67 (2=1)(3/12=0)(13=.), gen(russian)

keep q1var q2var q3var q4var q5var full1 full2 full5 police stranger beating policeXbeating strangerXbeating duty reward dutyXreward busy highval busyXhighval beatingXbusy beatingXhighval beatingXbusyXhighval beatingXduty beatingXreward beatingXdutyXreward age male material edu contact_any crimein12mo polstaknow newmoscow russian raion okrug

saveold "CWTS prepared data.dta", replace
